<template>
    <div v-if="detailsVisible">
        <el-table :data="recoderfilesTrue"  border  empty-text="请在 历次记录 中 双击 选择查看" :row-class-name="tableRowClassName">
            <el-table-column  width="65" label="标识" :show-overflow-tooltip='true' align="center">
                <template slot-scope="scope">
                    <img class="default-image" :src="$store.state.images.wujiaoxing" style="width：45px;height:45px;"> 
                </template> 
            </el-table-column>
            <el-table-column type="index" width="80" label="序号"  :index="indexbf" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column prop="createtime" width="100" label="年份"   :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column prop="alias" width="300" label="党委名称" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column prop="name" width="300" label="党支部名称" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column prop="type" width="170" label="姓名" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
             <el-table-column prop="bzxm" width="170" label="表彰项目" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column prop="bzdw" width="170" label="表彰单位" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column prop="bzsj" width="170" label="表彰时间" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column align="right">
                <template slot="header" slot-scope="scope">
                    <el-button  size="mini"    @click="serchfile">查询</el-button>
                    <el-button  size="mini"  @click="addfile" >新增</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination @size-change="SizeChangeB" @current-change="CurrentChangeB" :current-page.sync="currentPageB" :page-sizes="[10, 20, 50, 100]" :page-size="pageSizeB" layout="sizes,total, prev, pager, next" :total="totalB"></el-pagination>
        
        <Modal title="主题教育活动 筛选" v-model="Modalvisible" style="z-index:2999" @on-ok="onok('rowdata')">
            <el-form ref="rowdata" :model="rowdata" label-width="100px" class="personeditform" :rules="rules" status-icon>
                <el-form-item label="年份" >
                    <el-date-picker v-model="rowdata.createtime" type="year" placeholder="" value-format="yyyy"></el-date-picker>
                </el-form-item>
                <el-form-item label="单位" >
                    <el-select v-model="rowdata.dwid">
                        <el-option label="空" value="-1"></el-option>
                        <el-option v-for="item in alldws" :key="item.name" :label="item.name" :value="item.id"></el-option> 
                    </el-select>
                </el-form-item>
                
            </el-form>
        </Modal>
        <ztjyhdadd ref='ztjyhdadd' v-on:editResult="serchfileA"></ztjyhdadd>
    </div>
</template>
<script>
    import Common from "../../../js/Common.js";
    import {mapActions} from 'vuex';
    export default {
        data: () => ({
            detailsVisible:true,
            Modalvisible:false,
            alldws:[],
            rules: {
                time: [{ required: true, message: '不能为空', trigger: 'change' }],
            },
            showAdd:false,//显示添加的按钮,


            typeA:'组织建设',
            rowdata:{
                createtime:'',
                dwid:'',
                dzbid:'-1',
                type:'',
            },

            //第二个表格
            filetype:'上级文件',//文件分类 默认from
            Filerecode:'',//当前的记录id
            recoderfiles:[], //获取到的文件
            recoderfilesTrue:[],//真正在表格里面显示的 由于分页等原因

            // 表格分页
            currentPageB:1,//当前页码
            pageSizeB:10, //当前表格中显示的数据的总个数
            totalB:0 //默认一页显示数量

        }),
        mounted() {
            if(this.GetUser()==false){
                this.$router.push("/");
            }
            this.GetActiveDwId_DzbId();
             this.alldws=[];
            let _this=this; ;        
            this.GetZbById({dwid:-1,dzbid:-1})
            .then(function(data){
                for (let index = 0; index < data.childs.length; index++) {
                    const element = data.childs[index];
                    _this.alldws.push({
                        id:element.dwid,
                        name:element.alias
                    })
                }
            })
            
        },
        watch: {
            "detailsVisible": {
                handler(n) {
                    if(this.detailsVisible==true){
                       
                    }

                },
                deep: true
            }, 
        },
        components: {
            ztjyhdadd: function(resolve) {require(["./ztjyhdadd/ztjyhdadd.vue"], resolve);},
        },
        methods: {
            ...mapActions(['GetUser','GetZbById','GetActiveDwId_DzbId']),
            serchfile(){
                this.Modalvisible=true;
                this.rowdata.dwid=""
                this.recoderfilesTrue=[]
            },
            serchfileA(){
                this.recoderfiles=[];
                let _this=this;
                if(this.rowdata.dwid==""){
                    this.rowdata.dwid=-1;
                }
                console.log(this.rowdata);
                let postdata={
                    type:"serchfldj",
                    split:JSON.stringify(this.rowdata)
                }
                Common.AjaxPost(postdata,true)
                .then(function(e){
                    if(e.childs.length==0){
                        _this.$message({
                            message:'没有找到记录',
                            type:'info'
                        });
                    }
                    else{
                        _this.recoderfiles=e.childs; 
                        _this.showdataB();
                    }
                });
            },
            addfile(){
                this.$refs.ztjyhdadd.$data.dialogVisible = true;
            },
            showdataB(){
                this.totalB=this.recoderfiles.length;
                if (this.recoderfiles.length >= 0)
                {
                    let offset = (this.currentPageB - 1) * this.pageSizeB;
                    this.recoderfilesTrue=this.recoderfiles.slice(offset, this.pageSizeB+offset);
                }
            },
            SizeChangeB(val){
                this.pageSizeB = val;
                this.showdataB();
            },
            CurrentChangeB(val){
                this.currentPageB = val;
                this.showdataB();
            },
            indexbf(index){
                let offset = (this.currentPageB - 1) * this.pageSizeB;
                return index+offset+1;
            },
            fileCommand(value){
                let row=value.data;
                let typed=value.typed;
                let _this=this;
                if(typed=="delete"){
                    let postdata={
                        type:"deletefilerecoder",
                        split:JSON.stringify({
                            recoderfile:row.recoderfile,
                        })
                    }
                    Common.AjaxPost(postdata,true)
                    .then(function(e){
                         _this.$message('删除成功');
                         _this.serchfile();
                    })
                }
            },
            tableRowClassName({row, rowIndex}) {
                if (row.status === '已办') {
                    return 'success-row';
                
                } else if (row.status === '未办') {
                    return 'warning-row';
                }
                else if (row.status === '待办') {
                    return 'warning-row';
                }
            },
            onok(formName){

                this.serchfileA();
            },
            // checksubmit()
            // {
                
            // },
        }
    }
</script>
<style>
</style>